package treeview.unit;

import search.Visitor;
import treeview.AbstractNodeView;

import java.awt.*;

/**
 * Created by Pavel Nikolaev
 */
public abstract class AbstractUnitView extends AbstractNodeView {
    protected int myIndex = -1;
    protected int myReferenceOffset = -1;

    @Override
    public void accept(Visitor visitor) {
        visitor.visitUnitView(this);
    }

    public void setIndex(int index) {
        myIndex = index;
    }

    public int getIndex() {
        return myIndex;
    }

    public void highlight(Graphics g, Color color) {
        Color standardColor = g.getColor();
        g.setColor(color);
        g.fillRect(myX, myY, myWidth, myHeight);
        g.setColor(standardColor);
        paint(g);
    }

    // This method has different implementation only in TextView class
    public void highlight(Graphics g, int startOffset, int endOffset, Color color) {
        highlight(g, color);
    }

    public void setReferenceOffset(int offset) {
        myReferenceOffset = offset;
    }

    public int getStartOffset() {
        return myReferenceOffset;
    }

    public int getEndOffset() {
        return myReferenceOffset;
    }

    public int findOffset(int y) {
        return myReferenceOffset;
    }
}
